package silo.dungeonbuddy;

import java.net.Socket;

public class MultiThreadedClient implements Runnable
{
    protected boolean isStopped = false;
    protected Thread runningThread = null;
    protected Start game;

    public MultiThreadedClient(Start game)
    {
        this.game = game;
    }//constructor

    public void run()
    {
        synchronized(this)
        {
            this.runningThread = Thread.currentThread();
        }
        while(!isStopped())
        {
        	Socket clientSocket;
			try
			{
				clientSocket = new Socket(game.getServerIP(), 9000);
				new Thread(new RunnableClient(game,clientSocket)).start();
			}catch (Exception e)
			{
				//nothing
			}//catch e
        }
        System.out.println("Client Stopped.") ;
    }//run()


    private synchronized boolean isStopped()
    {
        return this.isStopped;
    }//isStopped()

    public synchronized void stop()
    {
        this.isStopped = true;
    }//stop()

}//class MultiThreadedServer